package API;

import java.io.UnsupportedEncodingException;
import java.util.Locale;

import android.nfc.NdefMessage;
import android.nfc.NdefRecord;

public class CreateMessageNFC {
	
	public static NdefRecord createRecord(String text)
	{

	    //create the message in according with the standard
	   // String lang = "fr";
	    byte[] textBytes = text.getBytes();
	    byte[] langBytes = null;
		try {
			langBytes = Locale.FRENCH.getLanguage().getBytes("US-ASCII");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    int langLength = langBytes.length;
	    int textLength = textBytes.length;

	    byte[] payload = new byte[1 + langLength + textLength];
	    payload[0] = (byte) langLength;

	    // copy langbytes and textbytes into payload
	    System.arraycopy(langBytes, 0, payload, 1, langLength);
	    System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);

	    NdefRecord recordNFC = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload);
	    return recordNFC;
	}
	
	public static NdefMessage createMessage(NdefRecord record)
	{
		NdefRecord[] records = new NdefRecord[1];
		records[0] = record;
		NdefMessage message = new NdefMessage(records);
		return message;
	}
	
	public static NdefRecord createName(String name){
		NdefRecord record = null;
		
		return record;
	}
}
